package com.ruoyi.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.entity.DTO.LegalAidLawyerDTO;
import com.ruoyi.entity.Evaluate;
import com.ruoyi.mapper.EvaluateMapper;
import com.ruoyi.service.EvaluateService;
import com.ruoyi.system.domain.LegalAidLawyer;
import com.ruoyi.system.mapper.LegalAidLawyerMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： dkl
 * @date： 2023/8/17
 * @description：
 */
@Service
public class EvaluateServiceImpl implements EvaluateService {

    @Autowired
    private LegalAidLawyerMapper legalAidLawyerMapper;
    @Autowired
    private EvaluateMapper evaluateMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    /**
     * 查看对律师的评论列表
     * @param id
     * @return
     */
    public List<Evaluate> getEvaluateByEvaluateId(Long id) {
        LegalAidLawyer legalAidLawyer = legalAidLawyerMapper.selectLegalAidLawyerById(id);
        Long evaluateId = legalAidLawyer.getEvaluateId();
        //1.获取律师的评论id
        legalAidLawyerMapper.selectLegalAidLawyerById(evaluateId);
        //2.根据 评论id去查询律师所对应的评论列表
        List<Evaluate> evaluateList = evaluateMapper.selectEvaluateById(evaluateId);
        //获取用户id 和用户头像 、昵称
        List<Evaluate> evaluateList1 = evaluateList.stream().map(item -> {
            Long userId = item.getUserId();
            SysUser user = sysUserMapper.selectUserById(userId);
            String nickName = user.getNickName();
            item.setNickName(nickName);
            String avatar = user.getAvatar();
            item.setAvatar(avatar);
            return item;

        }).collect(Collectors.toList());

        return evaluateList1;
    }
}
